package com.ywjt.platformbusiness.store.order.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseActivity;
import com.ywjt.platformbusiness.order.adapter.OrderListChild_Adapter;
import com.ywjt.platformbusiness.store.activity.SortingCenterActivity;
import com.ywjt.platformbusiness.store.order.model.StoreOrderListModel;
import com.ywjt.platformbusiness.util.WarningDialog;
import com.ywjt.platformbusiness.widget.CallPhoneBottomDialog;

import java.io.Serializable;


public class StoreOrderUnSend extends BaseActivity implements View.OnClickListener {
    private ImageView ivBack;
    private TextView tvGotoSend,tvName,tvPhone,tvAddress,tvOrdernum,tvOrderCreateTime,tvPayTime,tvPayType
            ,tvReMark,tvCopy,tvCallBuyer,tvGoodsMoney,tvTotalMoney,tvColoudGold;

    private RecyclerView rcView;

    private StoreOrderListModel.ResultDTO.RecordsDTO model;
    private OrderListChild_Adapter adapter;

    public static void actionStart(Context context, StoreOrderListModel.ResultDTO.RecordsDTO model) {
        Intent intent = new Intent(context, StoreOrderUnSend.class);
        intent.putExtra("model",(Serializable)model);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ivBack:
                finish();
                break;
            case R.id.tvGotoSend:
                SortingCenterActivity.actionStart(this,model,"1");
                break;
            case R.id.tvCallBuyer:
                //联系我们
                CallPhoneBottomDialog dialog=new CallPhoneBottomDialog(getContext());
                dialog.show(getSupportFragmentManager());
                break;

            case R.id.tvCopy:
                //复制订单号到剪切板
                copyText();
                break;
        }
    }
//
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void wxPaySuccess(EventBusBean eventBus){
//        switch (eventBus.getCode()){
//            case 78://课程目录点击事件
//                cancelOrder(eventBus.getMsg());
//                break;
//        }
//    }

    //实现复制订单号到剪切板
    public void copyText(){
        //获取剪贴板管理器：
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
// 创建普通字符型ClipData
        ClipData mClipData = ClipData.newPlainText("orderNUm",tvOrdernum.getText().toString().trim());
// 将ClipData内容放到系统剪贴板里。
        cm.setPrimaryClip(mClipData);
        Toast.makeText(StoreOrderUnSend.this,"已成功复制订单号到剪切板",Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.storeorde_unsend;
    }

    @Override
    protected void initView() {
//        if(!EventBus.getDefault().isRegistered(this)){//加上判断
//            EventBus.getDefault().register(this);
//        }
        model=(StoreOrderListModel.ResultDTO.RecordsDTO)getIntent().getSerializableExtra("model");
        ivBack=findViewById(R.id.ivBack);
        tvPayType=findViewById(R.id.tvPayType);
        tvPhone=findViewById(R.id.tvPhone);
        tvPayTime=findViewById(R.id.tvPayTime);
        tvCallBuyer=findViewById(R.id.tvCallBuyer);
        tvCopy=findViewById(R.id.tvCopy);
        tvTotalMoney=findViewById(R.id.tvTotalMoney);
        rcView=findViewById(R.id.rcView);
        tvColoudGold=findViewById(R.id.tvColoudGold);
        tvGoodsMoney=findViewById(R.id.tvGoodsMoney);
        tvAddress=findViewById(R.id.tvAddress);
        tvReMark=findViewById(R.id.tvReMark);
        tvOrdernum=findViewById(R.id.tvOrdernum);
        tvOrderCreateTime=findViewById(R.id.tvOrderCreateTime);
        tvName=findViewById(R.id.tvName);
        ivBack.setOnClickListener(this::onClick);
        tvGotoSend=findViewById(R.id.tvGotoSend);
        tvCallBuyer.setOnClickListener(this::onClick);
        tvGotoSend.setOnClickListener(this::onClick);
        tvCopy.setOnClickListener(this::onClick);

        if (model!=null){
            setView();
        }
   }

   public void setView(){
        tvName.setText(model.getReceiveName());
       tvPhone.setText(model.getReceivePhone());
       tvAddress.setText("地址："+model.getReceiveAddress());
       tvOrdernum.setText(model.getOrderNumber());
       tvOrderCreateTime.setText(model.getCreateTime());
       tvPayType.setText(model.getPayWay());
       tvPayTime.setText(model.getPayTime());
       tvReMark.setText("备注："+model.getRemark());
       tvGoodsMoney.setText(model.getTotalMoney()+"");
       tvTotalMoney.setText("¥"+model.getActuallyMoney());
       tvColoudGold.setText("-¥"+model.getDiscount());


       adapter=new OrderListChild_Adapter(model.getOrderDetailList(),1);
       rcView.setLayoutManager(new LinearLayoutManager(StoreOrderUnSend.this));
       rcView.setAdapter(adapter);
   }


    @Override
    protected void initData() {
        //getData();
    }

    @Override
    protected int getTitleBarType() {
        return TITLEBAR_NULL;
    }


    @Override
    protected void onPause() {
//        if(!EventBus.getDefault().isRegistered(this)){//加上判断
//            EventBus.getDefault().unregister(this);
//        }
        super.onPause();
    }

}
